package com.task.service.impl;

import com.task.bean.Rank;
import com.task.mapper.RankMapper;
import com.task.service.IRankService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.task.vo.RankNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuzhe
 * @since 2021-04-10
 */
@Service
public class RankServiceImpl extends ServiceImpl<RankMapper, Rank> implements IRankService {

    @Autowired
    private RankMapper rankMapper;

    @Override
    public List<RankNameVo> queryNameAndRankOrderByRank() {
            List<RankNameVo> rankNameVoList = rankMapper.queryNameAndRankOrderByRank();
            Collections.sort(rankNameVoList, new Comparator<RankNameVo>() {
                @Override
                public int compare(RankNameVo o1, RankNameVo o2) {
                    return (int) (o2.getRank() - o1.getRank());
                }
            });
            return rankNameVoList;

    }
}
